<?php
namespace app\models;

use myVendor\Factorys;
use Yii;
use yii\helpers\Inflector;
use yii\helpers\StringHelper;
use myVendor\DbProviderFactory;

class BaseModel{
    public $service;

    public function __construct() {
        $this->service=Factorys::getDbProvider(static::getModelName());
    }

    public static function getModelName(){
        return ucfirst(explode("_",Inflector::camel2id(StringHelper::basename(get_called_class()), '_'))[0]);
    }

    public function getAll($filters,$sorts,$limit,$skip){
        return $this->service->getAll($filters,$sorts,$limit,$skip);
    }

    public function getCount($filters){
        return $this->service->getCount($filters);
    }

    public function getOne($filters){
        return $this->service->getOne($filters);
    }

    public function getOneById($object_id){
        return $this->service->getOneById($object_id);
    }

    public function add($data){
        return $this->service->add($data);
    }

    public function update($data){
        return $this->service->update($data);
    }

    public function delete($object_id){
        return $this->service->delete($object_id);
    }
}